<?php
/**
 * Created by PhpStorm.
 * User: zyd
 * Date: 2019/2/25
 * Time: 20:12
 */

namespace app\shawting\controller;


class User extends Base
{
    public function index()
    {
        $search = input('search')?input('search'):"";
        $where["nick_name|duty"] = ["like","%{$search}%"];
        $arr = db("city_user")
            ->field("user_id,nick_name,avatar,mobile,company,duty,address,signature,card_style")
            ->where("delete_flag = 1")
            ->where($where)
            ->paginate(10,false, ['query'=> request()->param()]/*不丢失已存在的url参数]*/);
        $this->assign("arr",$arr);
        $this->assign("search",$search);
        return $this->fetch();
    }

    public function ajax_delete()
    {
        $id = input("id");
        if(!is_numeric($id)){
            return $this->error('查询数据格式不正确');
        }
        $result = db("city_user")->where(["user_id"=>$id])->delete();
        if(!$result){
            return $this->error("删除失败");
        }
        $this->success("删除成功");
    }

    public function merchant()
    {
        $search = input('search')?input('search'):"";
        $where["merchant_name|merchant_address"] = ["like","%{$search}%"];
        $arr = db("city_merchant")
            ->where("delete_flag = 1")
            ->where($where)
            ->paginate(10,false, ['query'=> request()->param()]/*不丢失已存在的url参数]*/);
        $merchant_serve = db("city_merchant_serve")->select();
        $this->assign("arr",$arr);
        $this->assign("search",$search);
        $this->assign("merchant_serve",$merchant_serve);
        return $this->fetch();
    }

    public function ajax_merchant_delete(){
        $id = input("id");
        if(!is_numeric($id)){
            return $this->error('查询数据格式不正确');
        }
        $result = db("city_merchant")->where(["id"=>$id])->update(["delete_flag"=>0]);
        if(!$result){
            return $this->error("删除失败");
        }
        $this->success("删除成功");
    }

    public function ajax_merchant_pass(){
        $id = input("id");
        $pass = input("pass");
        if(!is_numeric($id) || !is_numeric($pass)){
            return $this->error('查询数据格式不正确');
        }
        $result = db("city_merchant")->where(["id"=>$id])->update(["state"=>$pass]);
        if(!$result){
            return $this->error("操作失败");
        }
        $this->success("操作成功");
    }

    public function ajax_serve_edit(){
        $id = input("id");
        $serve = input("serve");
        if(!is_numeric($id) || empty($serve)){
            return $this->error('查询数据格式不正确');
        }
        if(strlen($serve) > 12){
            return $this->error("服务名称长度不能超过4个汉子".strlen($serve));
        }
        $result = db("city_merchant_serve")->where(["id"=>$id])->update(["serve"=>$serve]);
        if(!$result){
            return $this->error("操作失败");
        }
        $this->success("操作成功");
    }

    public function ajax_serve_show(){
        $id = input("id");
        $show = input("show");
        if(!is_numeric($id) || !is_numeric($show)){
            return $this->error('查询数据格式不正确');
        }
        $result = db("city_merchant_serve")->where(["id"=>$id])->update(["show_flag"=>$show]);
        if(!$result){
            return $this->error("操作失败");
        }
        $this->success("操作成功");
    }

































































}